package com.ychong.ychongwidget.ui

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.viewpager.widget.PagerAdapter
import com.bumptech.glide.Glide
import com.ychong.library.view.photoview.PhotoView
import com.ychong.ychongwidget.R
import com.ychong.ychongwidget.databinding.ActivityMorePhotoViewBinding


class MorePhotoViewActivity:AppCompatActivity() {
    private var binding:ActivityMorePhotoViewBinding? = null
    private var banners: MutableList<String> = arrayListOf(
        "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2561023669,2911685953&fm=26&gp=0.jpg",
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201805%2F26%2F20180526231242_wChzX.thumb.700_0.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1619600086&t=2898827595ea59d82c650f340f4d8b83",
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.mp.itc.cn%2Fupload%2F20170601%2F57acd7bc0d304dd18168c1097ace02e2_th.jpg&refer=http%3A%2F%2Fimg.mp.itc.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1619600124&t=cfd8935e738054f33ec32b30aa6fc223",
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F9167f4230c2c66d2b6b60f8722c1678ac4d743ed1b3bd-xg3GyI_fw658&refer=http%3A%2F%2Fhbimg.b0.upaiyun.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1619600148&t=accbe6127b3d9842a84b66787ad62557",
        "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3706660708,2115286006&fm=26&gp=0.jpg",
        "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=458192623,1716633452&fm=26&gp=0.jpg",
        "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2641602003,914992185&fm=26&gp=0.jpg",
        "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2561023669,2911685953&fm=26&gp=0.jpg",
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fstatic.jstv.com%2Fgather%2Fhl%2F20210318%2F38%2F7841821564275970690.jpg&refer=http%3A%2F%2Fstatic.jstv.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1619686259&t=ee0fd45d493e2ef848d9c567c9168f98"

    )
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_more_photo_view)

        binding!!.viewPager.pageMargin = (resources.displayMetrics.density * 15).toInt()
        binding!!.viewPager.adapter = object : PagerAdapter() {
            override fun getCount(): Int {
                return banners.size
            }

            override fun isViewFromObject(view: View, `object`: Any): Boolean {
                return view === `object`
            }

            override fun instantiateItem(container: ViewGroup, position: Int): Any {
                val view = PhotoView(this@MorePhotoViewActivity)
                view.enable()
                view.scaleType = ImageView.ScaleType.FIT_CENTER
                Glide.with(this@MorePhotoViewActivity).load(banners[position]).into(view)
                container.addView(view)
                return view
            }

            override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
                container.removeView(`object` as View)
            }
        }
    }
}